package com.pine.app.module.security.oauth.provider.client.dao.impl;

import com.pine.app.module.security.oauth.provider.client.dao.ScopeDao;
import com.pine.app.module.security.oauth.provider.client.entity.ScopeDetails;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.util.List;

/**
 * @author xiaoyuan
 * @create 2020/3/13 11:14
 **/
@Slf4j
public class ScopeDaoImpl implements ScopeDao {


    private final JdbcTemplate jdbcTemplate;

    public ScopeDaoImpl(DataSource dataSource){
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    private static  final  String  selectScopeListSql = "select client_id, scope, scope_name from oauth_client_scope where client_id = ?";
    @Override
    public List<ScopeDetails> getListByClientId(String clientId) {
       List<ScopeDetails> list =  jdbcTemplate.query(selectScopeListSql,new Object[]{clientId},(arg0, arg1) -> {
           ScopeDetails client = new ScopeDetails();
           client.setClient_id(arg0.getString("client_id"));
           client.setScope(arg0.getString("scope"));
           client.setScope_name(arg0.getString("scope_name"));
           return client;
       });
        return list;
    }
}
